const http = require("http");
const url = require("url");
const fs = require("fs");

const server=http.createServer((req,res)=>{
    res.setHeader("content-type","text/html;charset=utf-8");
    let urlObj = url.parse(req.url, true);
    let pathname = urlObj.pathname;
    if (pathname == "/") {
        console.log(urlObj)
        // 加载form表单
        let data = fs.readFileSync("./views/index.html");
        res.write(data);
        res.end();
    }else if(pathname=="/get"){
        console.log(urlObj)
        // get请求过来的内容
        //需求： 发送过来之后 显示出来提交的内容
        let query = urlObj.query;
        let {uname,age} =query;
        console.log(query)
        let content = '姓名：'+uname+"</br>"+"密码"+age
        content
        res.write(content);
        
        res.end();
    }
})

server.listen(8989)